package com.open.auth.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.open.auth.utils.SessionUtils;

@Controller
public class LoginPageController {

    /**
     * 跳转登陆页面方法
     * 
     * @param model
     * @return
     */
    @GetMapping("/auth/login")
    public String loginPage(Model model) {
        model.addAttribute("loginProcessUrl", "/auth/authorize");
        return "base-login";
    }

    /**
     * 登出
     */
    @GetMapping("/auth/logout")
    public String logout() {
    	/** 删除session */
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        SessionUtils.removeAttr(request , "SPRING_SECURITY_CONTEXT");
        SessionUtils.removeAttr(request , "org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository.CSRF_TOKEN");
        return "base-login";
    }
}
